﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace ATM
{
    public partial class Doimapin : Form
    {private SqlConnection conn;
   
        private SqlCommand cmd;
        public Doimapin(string s)
        {
            InitializeComponent();
            textBox1.Text = s;
        }

        private void Doimapin_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string con = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
            conn = new SqlConnection(con);
            cmd = new SqlCommand("select Acc_PIN from TB_ACCOUNT where Acc_No='" + textBox1.Text + "'", conn);
            conn.Open();

            SqlDataReader reader = cmd.ExecuteReader();
            reader.Read();
            string s = reader.GetValue(0).ToString();
            conn.Close();
            if (textBox2.Text != s)
            {
                MessageBox.Show("Mat khau khong dung");
            }
            else
            {
                if (textBox3.Text == "" || textBox4.Text == "") {
                    MessageBox.Show("Mat khau moi khong duoc de trong");
                }
                else
                {
                    if (textBox3.Text == textBox4.Text)
                    {

                        cmd = new SqlCommand("update TB_ACCOUNT set Acc_PIN ='" + textBox4.Text + "' where Acc_No='" + textBox1.Text + "'", conn);
                        conn.Open();
                        cmd.ExecuteNonQuery();
                        MessageBox.Show("Doi pin thanh cong");
                    }
                    else
                    {
                        MessageBox.Show("Hai mat khau moi khong giong nhau");


                    }
                }
                conn.Close();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            main f = new main(textBox1.Text);
            f.Show();
            this.Hide();
        }
    }
}
